<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>常用类-简单类 | 浪飞IT小栈</title>
    <meta name="generator" content="VuePress 1.9.9">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="前后端技术分享">
    <meta name="keywords" content="前端博客,后端博客,人工智能,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown,java,Spring,Springboot,Redis,mysql">
    <meta name="baidu-site-verification" content="7F55weZDDc">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.ada71c49.css" as="style"><link rel="preload" href="/assets/js/app.a2a00aa5.js" as="script"><link rel="preload" href="/assets/js/2.256f807a.js" as="script"><link rel="preload" href="/assets/js/22.55c868be.js" as="script"><link rel="prefetch" href="/assets/js/10.ab144fe3.js"><link rel="prefetch" href="/assets/js/11.062e0879.js"><link rel="prefetch" href="/assets/js/12.f9c60882.js"><link rel="prefetch" href="/assets/js/13.0a6ebfcf.js"><link rel="prefetch" href="/assets/js/14.03fc6f12.js"><link rel="prefetch" href="/assets/js/15.19dbf9fd.js"><link rel="prefetch" href="/assets/js/16.6e68160b.js"><link rel="prefetch" href="/assets/js/17.1d678834.js"><link rel="prefetch" href="/assets/js/18.4536fd5c.js"><link rel="prefetch" href="/assets/js/19.9c1b65df.js"><link rel="prefetch" href="/assets/js/20.c5f96e71.js"><link rel="prefetch" href="/assets/js/21.3f0b334e.js"><link rel="prefetch" href="/assets/js/23.91286241.js"><link rel="prefetch" href="/assets/js/24.c1af1909.js"><link rel="prefetch" href="/assets/js/25.a995a755.js"><link rel="prefetch" href="/assets/js/26.abc5dea3.js"><link rel="prefetch" href="/assets/js/27.1eb62850.js"><link rel="prefetch" href="/assets/js/28.b383a871.js"><link rel="prefetch" href="/assets/js/29.088e0d73.js"><link rel="prefetch" href="/assets/js/3.cd716564.js"><link rel="prefetch" href="/assets/js/30.3ccc98d5.js"><link rel="prefetch" href="/assets/js/31.aab7cc23.js"><link rel="prefetch" href="/assets/js/32.5e16b7e6.js"><link rel="prefetch" href="/assets/js/33.4aaeb741.js"><link rel="prefetch" href="/assets/js/34.45e8e898.js"><link rel="prefetch" href="/assets/js/35.5899c97a.js"><link rel="prefetch" href="/assets/js/36.32e2e263.js"><link rel="prefetch" href="/assets/js/37.c4e27bbd.js"><link rel="prefetch" href="/assets/js/38.fe5e60d2.js"><link rel="prefetch" href="/assets/js/39.2cb0b4ee.js"><link rel="prefetch" href="/assets/js/4.edf4d5e7.js"><link rel="prefetch" href="/assets/js/40.08d5bead.js"><link rel="prefetch" href="/assets/js/41.2f80f24b.js"><link rel="prefetch" href="/assets/js/42.43a49913.js"><link rel="prefetch" href="/assets/js/43.08da7ec2.js"><link rel="prefetch" href="/assets/js/44.7c7cb8a9.js"><link rel="prefetch" href="/assets/js/45.0ddf7e7f.js"><link rel="prefetch" href="/assets/js/46.7c4609a5.js"><link rel="prefetch" href="/assets/js/47.edf3ddf8.js"><link rel="prefetch" href="/assets/js/48.569a90b9.js"><link rel="prefetch" href="/assets/js/49.fa368ac8.js"><link rel="prefetch" href="/assets/js/5.24054156.js"><link rel="prefetch" href="/assets/js/50.b9b3ea7f.js"><link rel="prefetch" href="/assets/js/51.a2ebf0fe.js"><link rel="prefetch" href="/assets/js/52.31f02238.js"><link rel="prefetch" href="/assets/js/53.4110ef1e.js"><link rel="prefetch" href="/assets/js/54.dab741c7.js"><link rel="prefetch" href="/assets/js/55.f27984e9.js"><link rel="prefetch" href="/assets/js/56.bd4c1a8e.js"><link rel="prefetch" href="/assets/js/57.375d40cb.js"><link rel="prefetch" href="/assets/js/58.932e3864.js"><link rel="prefetch" href="/assets/js/59.e657be1b.js"><link rel="prefetch" href="/assets/js/6.b259c061.js"><link rel="prefetch" href="/assets/js/60.88d94274.js"><link rel="prefetch" href="/assets/js/61.fa71d884.js"><link rel="prefetch" href="/assets/js/62.a9d3b3b7.js"><link rel="prefetch" href="/assets/js/63.f849fe75.js"><link rel="prefetch" href="/assets/js/64.1770f7a9.js"><link rel="prefetch" href="/assets/js/65.6afc33db.js"><link rel="prefetch" href="/assets/js/66.799f2eb4.js"><link rel="prefetch" href="/assets/js/67.f36b2f7d.js"><link rel="prefetch" href="/assets/js/68.868cd00b.js"><link rel="prefetch" href="/assets/js/69.4c29b907.js"><link rel="prefetch" href="/assets/js/7.e34ea00f.js"><link rel="prefetch" href="/assets/js/70.1b993ed4.js"><link rel="prefetch" href="/assets/js/71.e16ad4f9.js"><link rel="prefetch" href="/assets/js/72.627505e6.js"><link rel="prefetch" href="/assets/js/73.32768e14.js"><link rel="prefetch" href="/assets/js/74.968a580d.js"><link rel="prefetch" href="/assets/js/75.42d5af3d.js"><link rel="prefetch" href="/assets/js/76.19a69d31.js"><link rel="prefetch" href="/assets/js/77.cf627a78.js"><link rel="prefetch" href="/assets/js/78.07177880.js"><link rel="prefetch" href="/assets/js/8.c4dd00ce.js"><link rel="prefetch" href="/assets/js/9.0ff73be2.js">
    <link rel="stylesheet" href="/assets/css/0.styles.ada71c49.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="浪飞IT小栈" class="logo"> <span class="site-name can-hide">浪飞IT小栈</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/avatar.jpg"> <div class="blogger-info"><h3>浪飞yes</h3> <span>无法简单的人儿~</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>开篇</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>基础语法</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>面向对象</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>常用类</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/d3f979/" aria-current="page" class="active sidebar-link">常用类-简单类</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/d3f979/#一、今日学习内容和目标" class="sidebar-link">一、今日学习内容和目标</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/d3f979/#_1-1-今日学习内容" class="sidebar-link">1.1 今日学习内容</a></li><li class="sidebar-sub-header level3"><a href="/pages/d3f979/#_1-2-今日学习目标" class="sidebar-link">1.2 今日学习目标</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/d3f979/#二、api-概述" class="sidebar-link">二、API 概述</a></li><li class="sidebar-sub-header level2"><a href="/pages/d3f979/#三、包装类" class="sidebar-link">三、包装类</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/d3f979/#_3-1-包装类概述-了解" class="sidebar-link">3.1 包装类概述（了解）</a></li><li class="sidebar-sub-header level3"><a href="/pages/d3f979/#_3-2-integer" class="sidebar-link">3.2 Integer</a></li><li class="sidebar-sub-header level4"><a href="/pages/d3f979/#_3-2-1-装箱和拆箱-掌握" class="sidebar-link">3.2.1  装箱和拆箱（掌握）</a></li><li class="sidebar-sub-header level4"><a href="/pages/d3f979/#_3-2-2-基本数据类型和字符串之间的转换" class="sidebar-link">3.2.2 基本数据类型和字符串之间的转换</a></li><li class="sidebar-sub-header level3"><a href="/pages/d3f979/#_3-3-bigdecimal-掌握" class="sidebar-link">3.3 BigDecimal（掌握）</a></li><li class="sidebar-sub-header level4"><a href="/pages/d3f979/#_3-3-1-构造器" class="sidebar-link">3.3.1 构造器</a></li><li class="sidebar-sub-header level4"><a href="/pages/d3f979/#_3-3-2-成员方法" class="sidebar-link">3.3.2 成员方法</a></li><li class="sidebar-sub-header level3"><a href="/pages/d3f979/#_3-4-string-掌握" class="sidebar-link">3.4 String（掌握）</a></li><li class="sidebar-sub-header level4"><a href="/pages/d3f979/#_3-4-1-string-本质概述-了解" class="sidebar-link">3.4.1 String 本质概述(了解)</a></li><li class="sidebar-sub-header level4"><a href="/pages/d3f979/#_3-4-2-常用方法-掌握" class="sidebar-link">3.4.2 常用方法(掌握)</a></li><li class="sidebar-sub-header level4"><a href="/pages/d3f979/#_3-4-3-可变字符串" class="sidebar-link">3.4.3 可变字符串</a></li><li class="sidebar-sub-header level5"><a href="/pages/d3f979/#构造器" class="sidebar-link">构造器</a></li><li class="sidebar-sub-header level5"><a href="/pages/d3f979/#成员方法" class="sidebar-link">成员方法</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/d3f979/#四、math" class="sidebar-link">四、Math</a></li><li class="sidebar-sub-header level2"><a href="/pages/d3f979/#五、random" class="sidebar-link">五、Random</a></li><li class="sidebar-sub-header level2"><a href="/pages/d3f979/#六、uuid" class="sidebar-link">六、UUID</a></li><li class="sidebar-sub-header level2"><a href="/pages/d3f979/#七、日期时间" class="sidebar-link">七、日期时间</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/d3f979/#_7-1-日期时间概述-了解" class="sidebar-link">7.1 日期时间概述 (了解)</a></li><li class="sidebar-sub-header level3"><a href="/pages/d3f979/#_7-2-date-掌握" class="sidebar-link">7.2 Date（掌握）</a></li><li class="sidebar-sub-header level3"><a href="/pages/d3f979/#_7-3-simpledateformat-掌握" class="sidebar-link">7.3 SimpleDateFormat（掌握）</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/d3f979/#八、小结与作业" class="sidebar-link">八、小结与作业</a></li></ul></li><li><a href="/pages/36ed35/" class="sidebar-link">常用类-数组高级</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>基础高级</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>数据库</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前端技术</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>热门框架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前后端分离</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>权限控制</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>NoSQL</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>微服务</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>消息中间件</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>脚手架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>技术增值</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><a href="/categories/?category=Java%E9%80%9F%E9%80%9A" title="分类" data-v-06225672>Java速通</a></li><li data-v-06225672><a href="/categories/?category=%E5%B8%B8%E7%94%A8%E7%B1%BB" title="分类" data-v-06225672>常用类</a></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/langfeiyes" target="_blank" title="作者" class="beLink" data-v-06225672>langfeiyes</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2024-03-03</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">常用类-简单类<!----></h1>  <div class="theme-vdoing-content content__default"><h1 id="常用类-简单类"><a href="#常用类-简单类" class="header-anchor">#</a> 常用类-简单类</h1> <h2 id="一、今日学习内容和目标"><a href="#一、今日学习内容和目标" class="header-anchor">#</a> 一、今日学习内容和目标</h2> <h3 id="_1-1-今日学习内容"><a href="#_1-1-今日学习内容" class="header-anchor">#</a> 1.1 今日学习内容</h3> <ul><li>八大基本类型的包装类
<ul><li>装箱和拆箱</li> <li>基本数据类型和字符串的转换</li></ul></li> <li>BigDecimal类
<ul><li>掌握BigDecimal的加减乘除和保留精度操作</li></ul></li> <li>String类
<ul><li>掌握String常用方法</li> <li>掌握可变字符串的常用方法</li></ul></li> <li>Math、Random、UUID
<ul><li>掌握常用方法</li></ul></li> <li>日期和时间
<ul><li>掌握Date类的使用</li> <li>掌握SimpleDateFormat的使用</li></ul></li> <li>熟悉查看API，熟悉方法调用</li></ul> <h3 id="_1-2-今日学习目标"><a href="#_1-2-今日学习目标" class="header-anchor">#</a> 1.2 今日学习目标</h3> <ul><li><p>八大基本类型封装类常用api</p></li> <li><p>BigDecimal、String、Math、Random、UUID、日期和时间 常用api</p></li></ul> <h2 id="二、api-概述"><a href="#二、api-概述" class="header-anchor">#</a> 二、API 概述</h2> <p>API ：Application Programming Interface，应用程序接口</p> <p>Java API ：指的就是 JDK 中提供的各种功能的 Java类
这些类将底层的实现封装了起来，我们不需要关心这些类是如何实现的，
只需要学习这些类如何使用即可，我们可以通过帮助文档来学习这些API如何使用</p> <h2 id="三、包装类"><a href="#三、包装类" class="header-anchor">#</a> 三、包装类</h2> <h3 id="_3-1-包装类概述-了解"><a href="#_3-1-包装类概述-了解" class="header-anchor">#</a> 3.1 包装类概述（了解）</h3> <p><strong>包装类的作用 :</strong></p> <ul><li>基本数据类型 , 没有方法 , 包装类就是让基本数据类型拥有变量和方法 , 实现对象化交互</li> <li>包装类核心功能：基本数据类型和字符串之间的转换</li></ul> <p>包装类位于 <code>java.lang</code> 包中，<strong>基本数据类型和包装类对应关系：</strong></p> <table><thead><tr><th>byte</th> <th>short</th> <th>int</th> <th>long</th> <th>float</th> <th>double</th> <th>char</th> <th>boolean</th></tr></thead> <tbody><tr><td>Byte</td> <td>Short</td> <td>Integer</td> <td>Long</td> <td>Float</td> <td>Double</td> <td>Character</td> <td>Boolean</td></tr></tbody></table> <p>除了Integer和Character外，其他都是讲基本类型的首字母大写。讲课单以Integer举例。</p> <h3 id="_3-2-integer"><a href="#_3-2-integer" class="header-anchor">#</a> 3.2 Integer</h3> <h4 id="_3-2-1-装箱和拆箱-掌握"><a href="#_3-2-1-装箱和拆箱-掌握" class="header-anchor">#</a> 3.2.1  装箱和拆箱（掌握）</h4> <p>装箱：把基本类型数据转成对应的包装类对象。
拆箱：把包装类对象转成对应的基本数据类型。</p> <p>装箱操作：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code>方式一：<span class="token class-name">Integer</span> num <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Integer</span><span class="token punctuation">(</span><span class="token number">17</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
方式二：<span class="token class-name">Integer</span> num <span class="token operator">=</span> <span class="token class-name">Integer</span><span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span><span class="token number">17</span><span class="token punctuation">)</span><span class="token punctuation">;</span>	<span class="token comment">//建议使用</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>拆箱操作：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token class-name">Integer</span>	num  <span class="token operator">=</span>  <span class="token class-name">Integer</span><span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span><span class="token number">17</span><span class="token punctuation">)</span><span class="token punctuation">;</span>	<span class="token comment">// 装箱操作</span>
<span class="token keyword">int</span> val <span class="token operator">=</span> num<span class="token punctuation">.</span><span class="token function">intValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>				<span class="token comment">// 拆箱操作</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>从Java5开始提供了的自动装箱（AutoBoxing）和自动拆箱（AutoUnBoxing）功能：</p> <p>​	自动装箱：可把一个基本类型变量直接赋给对应的包装类变量。</p> <p>​	自动拆箱：可以把包装类对象直接赋给对应的基本数据类型变量。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token class-name">Integer</span>	num  <span class="token operator">=</span>  <span class="token number">17</span><span class="token punctuation">;</span>	<span class="token comment">// 自动装箱操作</span>
<span class="token keyword">int</span> val <span class="token operator">=</span> num<span class="token punctuation">;</span>		<span class="token comment">// 自动拆箱操作</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>自动装箱和自动拆箱，在底层依然是手动装箱和手动拆箱。</p> <h4 id="_3-2-2-基本数据类型和字符串之间的转换"><a href="#_3-2-2-基本数据类型和字符串之间的转换" class="header-anchor">#</a> 3.2.2 基本数据类型和字符串之间的转换</h4> <p>通过Integer可以把字符串转化成int类型的数据</p> <ul><li>static int parseInt( string ) :  把字符串解析成一个整数并返回。</li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">IntegerDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">String</span> str <span class="token operator">=</span> <span class="token string">&quot;300&quot;</span><span class="token punctuation">;</span>
        <span class="token keyword">int</span> num <span class="token operator">=</span> <span class="token class-name">Integer</span><span class="token punctuation">.</span><span class="token function">parseInt</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;num = &quot;</span> <span class="token operator">+</span> num<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h3 id="_3-3-bigdecimal-掌握"><a href="#_3-3-bigdecimal-掌握" class="header-anchor">#</a> 3.3 BigDecimal（掌握）</h3> <p>问题：float和double都不能表示精确的小数</p> <p>解决方式：使用BigDecimal类可以解决该问题</p> <p>BigDecimal 提供给开发者的核心功能：用于处理任意精度要求高的数据（例如：互联网金融、移动支付等）。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">// 使用double类型计算  0.01 + 0.09</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token number">0.09</span> <span class="token operator">+</span> <span class="token number">0.01</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// ?</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h4 id="_3-3-1-构造器"><a href="#_3-3-1-构造器" class="header-anchor">#</a> 3.3.1 构造器</h4> <ul><li>public BigDecimal(String val) : 将 BigDecimal 的字符串表示形式转换为 BigDecimal</li></ul> <p>注意：必须使用<strong>字符串类型的构造器</strong></p> <h4 id="_3-3-2-成员方法"><a href="#_3-3-2-成员方法" class="header-anchor">#</a> 3.3.2 成员方法</h4> <p>主要是加减乘除四个操作。</p> <table><thead><tr><th><strong>方法声明</strong></th> <th><strong>描述</strong></th></tr></thead> <tbody><tr><td>public BigDecimal <strong>add</strong>(BigDecimal value)</td> <td>加法运算</td></tr> <tr><td>public BigDecimal <strong>subtract</strong>(BigDecimal value)</td> <td>减法运算</td></tr> <tr><td>public BigDecimal <strong>multiply</strong>(BigDecimal value)</td> <td>乘法运算</td></tr> <tr><td>public BigDecimal <strong>divide</strong>(BigDecimal divisor, int roundingMode)</td> <td>除法运算(除不尽，使用该方法)<br>参数说明：scale 精确位数  roundingMode取舍模式</td></tr> <tr><td>setScale</td> <td></td></tr></tbody></table> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 0.348</span>
    <span class="token class-name">BigDecimal</span> num1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">BigDecimal</span><span class="token punctuation">(</span><span class="token string">&quot;10.0&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">BigDecimal</span> num2 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">BigDecimal</span><span class="token punctuation">(</span><span class="token string">&quot;3.0&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token comment">// BigDecimal ret1 = num1.add(num2);		// 加法</span>
	<span class="token comment">// BigDecimal ret2 = num1.subtract(num2);   // 减法</span>

    <span class="token comment">//  保留位数</span>
    <span class="token comment">// RoundingMode 舍入模式</span>
    <span class="token comment">// RoundingMode.HALF_UP  表示四舍五入(常用)</span>
    <span class="token class-name">BigDecimal</span> ret1 <span class="token operator">=</span> big1<span class="token punctuation">.</span><span class="token function">multiply</span><span class="token punctuation">(</span>big2<span class="token punctuation">)</span><span class="token punctuation">;</span>		<span class="token comment">// 乘法</span>
    
    <span class="token comment">// 对结果保留2位小数 setScale(保留几位小数, 舍入模式)</span>
    <span class="token class-name">BigDecimal</span> ret2 <span class="token operator">=</span> ret1<span class="token punctuation">.</span><span class="token function">setScale</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token class-name">RoundingMode</span><span class="token punctuation">.</span><span class="token constant">HALF_UP</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>ret2<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">// 报错原因: 10.0 / 3.0 除不尽(3.333......)</span>
    <span class="token class-name">BigDecimal</span> ret4 <span class="token operator">=</span> num1<span class="token punctuation">.</span><span class="token function">divide</span><span class="token punctuation">(</span>num2<span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token class-name">RoundingMode</span><span class="token punctuation">.</span><span class="token constant">HALF_UP</span><span class="token punctuation">)</span><span class="token punctuation">;</span>		<span class="token comment">// 除法</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;ret4 = &quot;</span> <span class="token operator">+</span> ret4<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><p>上述代码分别表示乘法和除法按照四舍五入方式保留两位小数。</p> <h3 id="_3-4-string-掌握"><a href="#_3-4-string-掌握" class="header-anchor">#</a> 3.4 String（掌握）</h3> <p>字符串（字符序列），表示把多个字符按照一定得顺序连成的字符序列。</p> <p>字符串的分类（根据同一个对象，内容能不能改变而区分）：</p> <ul><li><p><strong>不可变的字符串——String</strong>：当String对象创建完毕之后，该对象的内容是不能改变的，一旦内容改变就变成了一个新的对象。</p></li> <li><p><strong>可变的字符串——StringBuilder/StringBuffer</strong>：当StringBuilder对象创建完毕之后，对象的内容可以发生改变，当内容发生改变的时候，对象保持不变。</p></li></ul> <h4 id="_3-4-1-string-本质概述-了解"><a href="#_3-4-1-string-本质概述-了解" class="header-anchor">#</a> 3.4.1 String 本质概述(了解)</h4> <p>String 类型表示字符串类，<strong>字符串的本质是char[]</strong>，char表示一个字符，char[] 表示字符类型的数组。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token class-name">String</span>  str <span class="token operator">=</span> <span class="token string">&quot;ABCD&quot;</span><span class="token punctuation">;</span>	
等价于	
<span class="token keyword">char</span><span class="token punctuation">[</span><span class="token punctuation">]</span> value <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token keyword">char</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token char">'A'</span><span class="token punctuation">,</span><span class="token char">'B'</span><span class="token punctuation">,</span><span class="token char">'C'</span><span class="token punctuation">,</span><span class="token char">'D'</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>1 String对象的两种创建方式</strong></p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token number">1</span>、直接赋一个字面量<span class="token operator">:</span>       <span class="token class-name">String</span>   str1  <span class="token operator">=</span>  <span class="token string">&quot;ABCD&quot;</span><span class="token punctuation">;</span><span class="token comment">//直接存储在堆区的常量池中,节约内存</span>
<span class="token number">2</span>、通过构造器创建<span class="token operator">:</span>         <span class="token class-name">String</span>   str2  <span class="token operator">=</span>  <span class="token keyword">new</span> <span class="token class-name">String</span><span class="token punctuation">(</span><span class="token string">&quot;ABCD&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>字符串内存图</strong></p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token class-name">String</span> str1 <span class="token operator">=</span> <span class="token string">&quot;hello&quot;</span><span class="token punctuation">;</span>
<span class="token class-name">String</span> str2 <span class="token operator">=</span> <span class="token string">&quot;hello&quot;</span><span class="token punctuation">;</span>
<span class="token class-name">String</span> str3 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">String</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>两种方式有什么区别，分别在内存中如何分布?</p> <p>通过<strong>字面量创建的字符串内存分配在常量池</strong>中，所以字面量字符串是常量；它们的值在创建之后不能更改。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/blog04-string.png" alt=""></p> <p>通过new 操作创建的字符串分配在堆区。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/blog04-string-new.png" alt=""></p> <p><strong>2 字符串的比较操作</strong></p> <ul><li><p>使用”==”号：比较两个字符串引用的内存地址是否相同</p></li> <li><p>使用equals方法：比较两个字符串的内容是否相同</p></li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span> <span class="token operator">==</span> <span class="token string">&quot;hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>						<span class="token comment">// true</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span> <span class="token operator">==</span> <span class="token keyword">new</span> <span class="token class-name">String</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>			<span class="token comment">// false</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>				<span class="token comment">// true</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">String</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>	<span class="token comment">// true</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>​</p> <p><strong>3 String类，表示不可变的字符串</strong></p> <p>当String对象创建完毕之后，该对象的内容是不能改变的，一旦内容改变就变成了一个新的对象，看下面代码。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token class-name">String</span> str <span class="token operator">=</span> <span class="token string">&quot;龙哥&quot;</span><span class="token punctuation">;</span>
str <span class="token operator">=</span> str <span class="token operator">+</span> <span class="token string">&quot;17&quot;</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/blog20240301130812.png" alt=""></strong></p> <p><strong>4 String对象的 &quot;空&quot; 值</strong></p> <div class="language-java line-numbers-mode"><pre class="language-java"><code>表示引用为空<span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">)</span>
<span class="token class-name">String</span>  str1 <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>   <span class="token comment">// 没有初始化，没有分配内存空间.  </span>

内容为空字符串
<span class="token class-name">String</span>  str2  <span class="token operator">=</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">;</span>     <span class="token comment">// 已经初始化，分配内存空间，不过没有内容</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h4 id="_3-4-2-常用方法-掌握"><a href="#_3-4-2-常用方法-掌握" class="header-anchor">#</a> 3.4.2 常用方法(掌握)</h4> <p>&quot;ABCD&quot;  看成   ['A','B','C,'D'] 来理解</p> <ul><li>int length() 返回此字符串的字符个数</li> <li>char charAt(int index) 返回指定索引位置的字符</li></ul> <p><strong>查找功能</strong></p> <ul><li>int indexOf(String str) 返回指定字符串str在此字符串中从左向右第一次出现处的索引位置</li> <li>boolean endWith(String suffix)</li> <li>boolean startWith(String prefix)</li></ul> <p><strong>比较功能</strong></p> <ul><li><p>boolean equals(Object anObject) 比较内容是否相同</p></li> <li><p>boolean equalsIgnoreCase(String anotherString) 忽略虑大小写，比较内容是否相同</p></li> <li><p>String toUpperCase()  把当前字符串转换为大写</p></li> <li><p>String toLowerCase()  把当前字符串转换为小写</p></li> <li><p>String substring(int beginIndex)：从指定位置开始截取字符串，直到最后</p></li> <li><p>String substring(int beginIndex, int endIndex)：截取指定区域的字符串</p></li> <li><p>String replace(String oldStr,  String newStr)</p></li> <li><p>String trim() 返回一个字符串，其值为此字符串，并删除任何前导和尾随空格。</p></li></ul> <p>需求1：模拟用户登录</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">StringDemo3</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">/**
         * 1 控制台输入用户名和密码
         * 2 拿用户输入的用户名和密码和之前注册的用户名和密码比较内容是否相等
         * 3 登录成功的业务（用户名和密码都输入正确）？ 成功 : 失败
         */</span>
        <span class="token comment">// 1 控制台输入用户名和密码</span>
        <span class="token class-name">Scanner</span> sc <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Scanner</span><span class="token punctuation">(</span><span class="token class-name">System</span><span class="token punctuation">.</span>in<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;请输入用户名:&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">String</span> iptName <span class="token operator">=</span> sc<span class="token punctuation">.</span><span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;请输入密码:&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">String</span> iptPwd <span class="token operator">=</span> sc<span class="token punctuation">.</span><span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// 2 拿用户输入的用户名和密码和之前注册的用户名和密码比较内容是否相等</span>
        <span class="token class-name">String</span> userName <span class="token operator">=</span> <span class="token string">&quot;will&quot;</span><span class="token punctuation">;</span>
        <span class="token class-name">String</span> pwd <span class="token operator">=</span> <span class="token string">&quot;123&quot;</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>iptName<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>userName<span class="token punctuation">)</span> <span class="token operator">&amp;&amp;</span> iptPwd<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>pwd<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;登录成功&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;用户名或密码错误&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><p>需求2：手机号码,屏蔽中间四位</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">PhoneDemo</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 1</span>
		<span class="token class-name">Scanner</span> sc <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Scanner</span><span class="token punctuation">(</span><span class="token class-name">System</span><span class="token punctuation">.</span>in<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;请输入一个手机号码:&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">String</span> phone <span class="token operator">=</span> sc<span class="token punctuation">.</span><span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// 2</span>
        <span class="token class-name">String</span> str1 <span class="token operator">=</span> phone<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 3</span>
        <span class="token class-name">String</span> str2 <span class="token operator">=</span> phone<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// 4</span>
        <span class="token class-name">String</span> newPhone <span class="token operator">=</span> str1 <span class="token operator">+</span> <span class="token string">&quot;****&quot;</span> <span class="token operator">+</span> str2<span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;newPhone = &quot;</span> <span class="token operator">+</span> newPhone<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><h4 id="_3-4-3-可变字符串"><a href="#_3-4-3-可变字符串" class="header-anchor">#</a> 3.4.3 可变字符串</h4> <p><strong>需要对同一字符串对象内容进行修改操作，就需要可变字符串</strong>——<strong>StringBuilder</strong>,位于 java.lang 包中。</p> <p>StringBuilder包含了一个字符数组，可以调用方法向字符数组进行<strong>增加</strong>、删除、修改字符</p> <p>我们完全可以把StringBuilder看成一个&quot;<strong>字符或者字符串的容器</strong>&quot;!</p> <p><strong>可变字符串内存图</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/blogimage-20220305131642476.png" alt=""></p> <h5 id="构造器"><a href="#构造器" class="header-anchor">#</a> 构造器</h5> <ul><li><strong>StringBuilder()</strong> : 初始化默认容量是16的可变字符串</li> <li>StringBuilder(int capacity)  初始化容量是capacity的可变字符串</li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 创建一个可变字符串容器，默认容量是16个字符</span>
    <span class="token class-name">StringBuffer</span> sb <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">StringBuffer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// 创建一个可变字符串容器，容量是26个字符</span>
    <span class="token class-name">StringBuffer</span> sb2 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">StringBuffer</span><span class="token punctuation">(</span><span class="token number">26</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h5 id="成员方法"><a href="#成员方法" class="header-anchor">#</a> 成员方法</h5> <ul><li><strong>public StringBuilder append( xx )</strong></li> <li>public int length()</li> <li>public int capacity()</li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    
    <span class="token class-name">StringBuffer</span> sb <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">StringBuffer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// 追加操作(在末尾添加)</span>
    sb<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    sb<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token number">17</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>sb<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// hello17</span>

    <span class="token comment">// 查询（字符个数，容量,打印容器中的字符）操作</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;容器中的字符个数：&quot;</span> <span class="token operator">+</span> sb<span class="token punctuation">.</span><span class="token function">length</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>	<span class="token comment">// 7</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;容器的容量：&quot;</span> <span class="token operator">+</span> sb<span class="token punctuation">.</span><span class="token function">capacity</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     <span class="token comment">// 16</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="四、math"><a href="#四、math" class="header-anchor">#</a> 四、Math</h2> <p>概述 : Math包含执行数学运算的方法，如取整数，求最大值和最小值，随机数等。所提供的都是静态方法，可以直接调用</p> <p>Math类位于java.lang包中。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		
		<span class="token comment">// 1 取整操作 ceil/floor</span>
		<span class="token keyword">float</span> a <span class="token operator">=</span> <span class="token number">9.2f</span><span class="token punctuation">;</span>
		<span class="token comment">// Math.ceil(a) 比9.2大或等于的最小整数：向上取整</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">ceil</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// Math.floor(a) 比9.2小或等于的最大整数：向下取整		</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		
		<span class="token comment">// 2 求最大值和最小值</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">max</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		
		<span class="token comment">// 3 随机数 取值返回[0.0,1.0)</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h2 id="五、random"><a href="#五、random" class="header-anchor">#</a> 五、Random</h2> <p>Random类用于产生一个随机数的，位于<code>java.util</code>包中。</p> <p><strong>常用方法</strong></p> <ul><li>nextInt(int n) : 产生范围在 [0 , n) 的随机整数</li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 创建一个Random对象</span>
    <span class="token class-name">Random</span> r <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// val的范围[0,100]之间</span>
    <span class="token keyword">int</span> val <span class="token operator">=</span> r<span class="token punctuation">.</span><span class="token function">nextInt</span><span class="token punctuation">(</span><span class="token number">101</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>val<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="六、uuid"><a href="#六、uuid" class="header-anchor">#</a> 六、UUID</h2> <p>UUID 用于生成<strong>唯一</strong>标识符 (Universally Unique Identifier) ，优点是真实的唯一性，缺点是字符串太长了。</p> <p>UUID位于 <code>java.util</code> 包中，jdk1.5 才出现的类</p> <p><strong>常用方法</strong></p> <ul><li>randomUUID() : 产生一个随机的唯一标识符，格式：678f9568-8967-4637-a48e-f0eae30faf43</li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 创建UUID对象</span>
    <span class="token class-name">UUID</span> uuid <span class="token operator">=</span> <span class="token constant">UUID</span><span class="token punctuation">.</span><span class="token function">randomUUID</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// 获取UUID对象中的唯一标识符存入字符串中</span>
    <span class="token class-name">String</span> str <span class="token operator">=</span> uuid<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;str = &quot;</span> <span class="token operator">+</span> str<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="七、日期时间"><a href="#七、日期时间" class="header-anchor">#</a> 七、日期时间</h2> <h3 id="_7-1-日期时间概述-了解"><a href="#_7-1-日期时间概述-了解" class="header-anchor">#</a> 7.1 日期时间概述 (了解)</h3> <p><strong>时间戳（timestamp）</strong>：具体时间（特定的瞬间）距离历元(1970年01月01日 00:00:00:000) 经过的毫秒数，用long类型存储。时间戳可以很容易被解释(转换)为年、月、日、小时、分钟和秒值。</p> <h3 id="_7-2-date-掌握"><a href="#_7-2-date-掌握" class="header-anchor">#</a> 7.2 Date（掌握）</h3> <p>Date类，日期时间类，表示特定的瞬间，可以解释为年、月、日、小时、分钟和秒值。</p> <p>注意：我们使用的是java.util.Date类，而不是java.sql.Date。</p> <p>Date类中的大量方法都标记为已经过时的，即官方不建议使用。在开发中，我们要表示日期（年月日）或时间（时分秒）类型都使用Date类来表示。</p> <p><strong>常用方法</strong></p> <ul><li>Date()</li> <li>getTime()</li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">DateDemo</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		
		<span class="token comment">// 根据电脑当前日期时间构建一个Date对象</span>
    	<span class="token class-name">Date</span> now <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    	<span class="token comment">// Wed Aug 11 10:52:20 CST(chinese standard time) 2021</span>
    	<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>now<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		
		<span class="token comment">// 获取Date对象的时间戳(例如:161231345464)</span>
		<span class="token keyword">long</span> ts <span class="token operator">=</span> now<span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>ts<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="_7-3-simpledateformat-掌握"><a href="#_7-3-simpledateformat-掌握" class="header-anchor">#</a> 7.3 SimpleDateFormat（掌握）</h3> <p>​		打印Date对象时，默认打印的是欧美人的日期时间风格，如果需要输出自定义的时间格式，比如2020年12月12日 12:12:12格式或者2020-12-12 12:12:12，此时可以使用SimpleDateFormat类。</p> <p>SimpleDateFormat类，顾名思义是日期的格式化类，主要包括两个功能的方法：</p> <ul><li>格式化（format）：Date类型转换为String类型：String format(Date date)</li> <li>解析（parse）：String类型转换为Date类型：Date parse(String source)</li></ul> <p>无论是格式化还是解析都需要设置日期时间的模式，所谓模式就是一种格式( xxxx年xx月xx日 xx时xx分xx秒 )。</p> <p><strong><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/blogimagepic140.png" alt=""></strong></p> <p>日期时间模式举例：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>yyyy-MM-dd							如2020-12-12
HH:mm:ss							如20:12:12
yyyy-MM-dd HH:mm:ss					如2020-12-12 20：12：12
yyyy/MM/dd HH:mm:ss					如2020/12/12 20：12：12
yyyy年MM月dd日 HH时mm分ss秒			如2020年12月12日 20时12分12秒
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>格式化和解析代码如下：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>text<span class="token punctuation">.</span></span><span class="token class-name">ParseException</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>text<span class="token punctuation">.</span></span><span class="token class-name">SimpleDateFormat</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">Date</span></span><span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SimpleDateFormatDemo</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">ParseException</span> <span class="token punctuation">{</span>
        
		<span class="token class-name">Date</span> date <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 创建SimpleDateFormat对象</span>
		<span class="token class-name">SimpleDateFormat</span> df <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDateFormat</span><span class="token punctuation">(</span><span class="token string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        
		<span class="token comment">// 格式化（format）：Date类型转换为String类型：String format(Date date)</span>
		<span class="token class-name">String</span> dateStr <span class="token operator">=</span> df<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>date<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>dateStr<span class="token punctuation">)</span><span class="token punctuation">;</span>
        
		<span class="token comment">// 解析（parse）：String类型转换为Date类型：Date parse(String source)</span>
		<span class="token class-name">Date</span> date2 <span class="token operator">=</span> df<span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span>dateStr<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>date2<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><p>代码中public static void main(String[] args) throws Exception表示抛出异常，在main方法中不作任何处理，在异常章节再细讲。</p> <h2 id="八、小结与作业"><a href="#八、小结与作业" class="header-anchor">#</a> 八、小结与作业</h2> <ul><li>包装类基本使用-建议5遍</li> <li>BigDecimal类基本使用-建议5遍</li> <li>String类基本使用-建议5遍</li> <li>Math类基本使用-建议5遍</li> <li>Random类基本使用-建议5遍</li> <li>UUID类基本使用-建议5遍</li> <li>日期与时间类基本使用-建议5遍</li></ul></div></div>  <div class="page-edit"><!----> <div class="tags"><a href="/tags/?tag=%E5%B8%B8%E7%94%A8%E7%B1%BB" title="标签">#常用类</a></div> <!----></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/efafe7/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">查漏补缺</div></a> <a href="/pages/36ed35/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">常用类-数组高级</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/efafe7/" class="prev">查漏补缺</a></span> <span class="next"><a href="/pages/36ed35/">常用类-数组高级</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/0c07b2/"><div>
            IT杂货铺
            <!----></div></a> <span class="date">03-23</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/705b35/"><div>
            人事百问
            <!----></div></a> <span class="date">03-22</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/78eb56/"><div>
            MyBatis-Plus
            <!----></div></a> <span class="date">03-12</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:langfeiyes@163.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/langfeiyes" title="GitHub" target="_blank" class="iconfont icon-github"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2024-2024
    <span><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备18007927号-1</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.a2a00aa5.js" defer></script><script src="/assets/js/2.256f807a.js" defer></script><script src="/assets/js/22.55c868be.js" defer></script>
  </body>
</html>
